// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package main

import (
	"regexp"

	"go.chromium.org/luci/common/data/stringset"
)

var (
	pythonVersionRegex = regexp.MustCompile("^\\d\\.\\d{1,2}.\\d{1,2}$")

	gitVersionRegex = regexp.MustCompile("^\\d\\.\\d{1,2}.\\d{1,2}$")

	knownCommands = stringset.NewFromSlice(
		"gclient config",
		"gclient diff",
		"gclient fetch",
		"gclient flatten",
		"gclient getdep",
		"gclient grep",
		"gclient help",
		"gclient metrics",
		"gclient pack",
		"gclient recurse",
		"gclient revert",
		"gclient revinfo",
		"gclient root",
		"gclient runhooks",
		"gclient setdep",
		"gclient status",
		"gclient sync",
		"gclient validate",
		"gclient verify",
		"git cl archive",
		"git cl baseurl",
		"git cl checkout",
		"git cl comments",
		"git cl config",
		"git cl creds-check",
		"git cl commit",
		"git cl description",
		"git cl diff",
		"git cl format",
		"git cl help",
		"git cl issue",
		"git cl land",
		"git cl lint",
		"git cl owners",
		"git cl patch",
		"git cl presubmit",
		"git cl set-close",
		"git cl set-commit",
		"git cl split",
		"git cl status",
		"git cl tree",
		"git cl try",
		"git cl try-results",
		"git cl upload",
		"git cl upstream",
		"git cl web",
		"git nav-downstream",
	)

	knownArguments = stringset.NewFromSlice(
		"A",
		"D",
		"H",
		"M",
		"R",
		"a",
		"abort",
		"access_key_id",
		"actions",
		"activate_update",
		"actual",
		"add_comment",
		"add_owners_to",
		"all",
		"append",
		"archive",
		"assume_yes",
		"auth_host_port",
		"auth_refresh_token_json",
		"author",
		"auto_platform",
		"auto_rebase",
		"b",
		"batch",
		"begin",
		"bot",
		"boto",
		"branch",
		"break_repo_locks",
		"bucket",
		"bug",
		"build_dir",
		"buildbucket_host",
		"bypass_hooks",
		"bypass_watchlists",
		"c",
		"cache_dir",
		"category",
		"cc",
		"changes",
		"changes_by_issue",
		"cherry_pick",
		"cleanup_dir",
		"clear",
		"clobber",
		"clober",
		"color",
		"comment",
		"comment_file",
		"commit",
		"complete",
		"completed_issues",
		"config",
		"config_filename",
		"count",
		"cq_dry_run",
		"curAnim",
		"custom_vars",
		"d",
		"deactivate_update",
		"debug",
		"debugger",
		"default_presubmit",
		"delete_unversioned_trees",
		"deltas",
		"dependencies",
		"depends_on_patchset",
		"deps",
		"deps_file",
		"deps_os",
		"depth",
		"description",
		"description_file",
		"diff",
		"directory",
		"disable_syntax_validation",
		"display",
		"download_base",
		"dry_run",
		"dryrun",
		"duration",
		"easing",
		"email",
		"emulate_svn_auto_props",
		"enable_auto_submit",
		"enable_metrics",
		"end",
		"entries_filename",
		"eol",
		"erase_first",
		"extract",
		"f",
		"fail_under",
		"fast",
		"field",
		"file",
		"file_path",
		"filter",
		"force",
		"forced_codereview",
		"full",
		"gclientfile",
		"gerrit",
		"gerrit_fetch",
		"gerrit_no_rebase_patch_ref",
		"gerrit_no_reset",
		"gerrit_url",
		"getdep_revisions",
		"git_cache_dir",
		"git_find_copies",
		"git_find_copies_harder",
		"git_similarity",
		"gzip",
		"hashtags",
		"head",
		"help",
		"help_commands",
		"help_filters",
		"hide",
		"i",
		"ignore",
		"ignore_current",
		"ignore_dep_type",
		"ignore_errors",
		"ignore_locks",
		"ignore_self",
		"include",
		"instance_url",
		"issue",
		"issues",
		"iteritems",
		"j",
		"jobs",
		"js",
		"json",
		"json_file",
		"keypair",
		"keys",
		"large",
		"last_quarter",
		"last_week",
		"leave",
		"local_user",
		"lock_timeout",
		"m",
		"machine_readable",
		"manually_grab_svn_rev",
		"markdown",
		"master",
		"maxjobs",
		"may_prompt",
		"merge",
		"merged_only",
		"message",
		"message_file",
		"module",
		"n",
		"name",
		"new_description",
		"newbranch",
		"no_auth",
		"no_autocc",
		"no_bootstrap",
		"no_branch_color",
		"no_color",
		"no_commit",
		"no_download",
		"no_history",
		"no_nag_max",
		"no_progress",
		"no_rebase_patch_ref",
		"no_referenced_issues",
		"no_reset_patch_ref",
		"no_squash",
		"no_verify_revision",
		"nocommit",
		"nohooks",
		"noprehooks",
		"notags",
		"null",
		"num_instances",
		"num_threads",
		"num_upload_threads",
		"omit",
		"opt_in",
		"opt_out",
		"orig",
		"outfile",
		"output",
		"output_config_file",
		"output_deps",
		"output_deps_files",
		"output_format",
		"output_format_changes",
		"output_format_heading",
		"output_format_issues",
		"output_format_no_url",
		"output_format_reviews",
		"output_json",
		"overflow",
		"override_dir",
		"p",
		"p4_changelist",
		"p4_client",
		"p4_port",
		"p4_user",
		"parallel",
		"parallel_mode",
		"parent_checkout",
		"patch_ref",
		"patch_refs",
		"patch_root",
		"patchset",
		"path",
		"pin_all_deps",
		"platform",
		"prepend_dir",
		"preserve_tryjobs",
		"presubmit",
		"print_diffs",
		"print_master",
		"private",
		"process_all_deps",
		"project",
		"properties",
		"prune",
		"publish",
		"pull",
		"pylib",
		"python",
		"quiet",
		"r",
		"r_owners",
		"rcfile",
		"read",
		"readable",
		"reapply",
		"rebase_patch_ref",
		"recursive",
		"ref",
		"refs",
		"region",
		"reject",
		"repackage_dir",
		"reset",
		"reset_fetch_config",
		"reset_patch_ref",
		"resume",
		"return_value",
		"reverse",
		"reviewer",
		"reviewers",
		"reviews",
		"revision",
		"revision_mapping",
		"revision_mapping_file",
		"revisions",
		"rietveld",
		"root",
		"s",
		"save_cookies",
		"scm",
		"secret_key",
		"send_mail",
		"send_patch",
		"server",
		"setdefault",
		"setdep_revisions",
		"sha1_file",
		"shallow",
		"show",
		"show_all",
		"show_missing",
		"since",
		"skip_canned",
		"skip_hashing",
		"skip_own_issues_without_changes",
		"sleep_first",
		"sleep_last",
		"snapshot",
		"source",
		"spec",
		"spec_path",
		"specialEasing",
		"specs",
		"squash",
		"stat",
		"stderr",
		"stdout",
		"step",
		"t",
		"target_branch",
		"target_ref",
		"tbr_owners",
		"tbrs",
		"this_year",
		"timeout",
		"timid",
		"title",
		"toolchain_dir",
		"topic",
		"transitive",
		"u",
		"unmanaged",
		"update",
		"upload",
		"upstream",
		"url",
		"use_commit_queue",
		"use_local_webserver",
		"use_md5",
		"use_null_terminator",
		"use_oauth2",
		"user",
		"v",
		"validate_syntax",
		"var",
		"vars",
		"vcs",
		"verbose",
		"verbosity",
		"version",
		"week_of",
		"winver",
		"with_branch_heads",
		"with_tags",
	)

	knownProjectURLs = stringset.NewFromSlice(
		"https://chrome-internal.googlesource.com/chrome/ios_internal",
		"https://chrome-internal.googlesource.com/infra/infra_internal",
		"https://chromium.googlesource.com/breakpad/breakpad",
		"https://chromium.googlesource.com/chromium/src",
		"https://chromium.googlesource.com/chromium/tools/depot_tools",
		"https://chromium.googlesource.com/crashpad/crashpad",
		"https://chromium.googlesource.com/external/gyp",
		"https://chromium.googlesource.com/external/naclports",
		"https://chromium.googlesource.com/infra/goma/client",
		"https://chromium.googlesource.com/infra/infra",
		"https://chromium.googlesource.com/native_client/",
		"https://chromium.googlesource.com/syzygy",
		"https://chromium.googlesource.com/v8/v8",
		"https://dart.googlesource.com/sdk",
		"https://pdfium.googlesource.com/pdfium",
		"https://skia.googlesource.com/buildbot",
		"https://skia.googlesource.com/skia",
		"https://webrtc.googlesource.com/src",
	)

	knownOSs = stringset.NewFromSlice(
		"android",
		"fuchsia",
		"ios",
		"linux",
		"mac",
		"win",
	)

	knownArchs = stringset.NewFromSlice(
		"AMD64",
		"arm",
		"arm64",
		"ia32",
		"mips",
		"ppc",
		"s390",
		"x64",
		"x86",
	)

	knownHTTPHosts = stringset.NewFromSlice(
		"chrome-internal-review.googlesource.com",
		"chromium-review.googlesource.com",
		"dart-review.googlesource.com",
		"eu1-mirror-chromium-review.googlesource.com",
		"pdfium-review.googlesource.com",
		"skia-review.googlesource.com",
		"us1-mirror-chromium-review.googlesource.com",
		"us2-mirror-chromium-review.googlesource.com",
		"us3-mirror-chromium-review.googlesource.com",
		"webrtc-review.googlesource.com",
	)

	knownHTTPMethods = stringset.NewFromSlice(
		"DELETE",
		"GET",
		"PATCH",
		"POST",
		"PUT",
	)

	knownHTTPPaths = stringset.NewFromSlice(
		"accounts",
		"changes",
		"changes/abandon",
		"changes/comments",
		"changes/detail",
		"changes/edit",
		"changes/message",
		"changes/restore",
		"changes/reviewers",
		"changes/revisions/commit",
		"changes/revisions/review",
		"changes/submit",
		"projects/branches",
	)

	knownHTTPArguments = stringset.NewFromSlice(
		"ALL_REVISIONS",
		"CURRENT_COMMIT",
		"CURRENT_REVISION",
		"DETAILED_ACCOUNTS",
		"LABELS",
	)

	knownSubCommands = stringset.NewFromSlice(
		"git push",
		"presubmit",
	)

	knownSubCommandArguments = stringset.NewFromSlice(
		"cc",
		"hashtag",
		"l=Auto-Submit+1",
		"l=Code-Review+1",
		"l=Code-Review+2",
		"l=Commit-Queue+1",
		"l=Commit-Queue+2",
		"label",
		"m",
		"notify=ALL",
		"notify=NONE",
		"private",
		"r",
		"ready",
		"topic",
		"wip",
	)
)
